package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC1535 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int getWinner(int[] arr, int k) {
            if (k > arr.length) k = arr.length;
            int curWinner = arr[0];
            int curWinCount = 0;
            for (int i = 1; curWinCount < k; i++) {
                if (arr[i % arr.length] > curWinner) {
                    curWinCount = 1;
                    curWinner = arr[i % arr.length];
                } else ++curWinCount;
            }

            return curWinner;
        }
    }


    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[2,1,3,5,4,6,7]");
        System.out.println(solution.getWinner(arr, 2));
    }

    public static void main(String[] args) throws Exception {
        LC1535 an = new LC1535();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
